package com.sp.reactive;

import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-04-16 16:04:26
 */
public class CombiningTest {

    @Test
    public void test4() {
        Flux<Integer> j1 = Flux.just(1, 2);
        Flux<Integer> j2 = Flux.just(3, 4);
        Flux.zip(j1, j2).subscribe(System.out::println);
    }

    @Test
    public void test3() {
        Flux.merge(Flux.interval(Duration.ofSeconds(1)).take(1),
                        Flux.interval(Duration.ofSeconds(2)).take(2))
                .toStream()
                .forEach(System.out::println);
    }

    @Test
    public void test2() throws Exception {
        Mono.when(Flux.just(1, 2), Flux.range(5, 10))
                .subscribe(System.out::println);

        TimeUnit.SECONDS.sleep(3);
    }

    @Test
    public void test1() {
        Flux.just(1, 2, 3)
                .then()
                .subscribe(System.out::println);
    }
}
